/**
 * 
 */
package com.ffcs.crmd.tsp.task.container;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.ffcs.crmd.tsp.core.container.AbstractContainer;
import com.ffcs.crmd.tsp.task.threadpool.JobProcessBusinessThreadPool;
import com.ffcs.crmd.tsp.task.threadpool.JobProcessThreadPool;

/**
 * 功能说明:线程池容器
 *
 * @author ZHONGFUHUA
 * 
 * @since 2.0.0-SNAPSHOT
 *
 */
public class ThreadPoolContainer extends AbstractContainer {
    
    private static ThreadPoolContainer   threadPoolContainer = new ThreadPoolContainer();
    
    /**
     * 任务批量业务处理线程池
     */
    private JobProcessBusinessThreadPool jobProcessBussinessThreadPool;
    
    /**
     * 任务处理线程池
     */
    private JobProcessThreadPool         jobProcessThreadPool;
    
    protected ThreadPoolContainer() {
        
    }
    
    public static ThreadPoolContainer getInstance() {
        return threadPoolContainer;
    }
    
    @Override
    public void register(Object object) {
        List<Class<?>> clazzs = new ArrayList<Class<?>>();
        clazzs.add(this.getClass());
        if (CollectionUtils.isNotEmpty(clazzs)) {
            for (Class<?> clazz : clazzs) {
                Field[] fields = clazz.getDeclaredFields();
                if (fields != null && fields.length > 0) {
                    for (int i = 0; i < fields.length; i++) {
                        if (fields[i].getType().equals(object.getClass())) {
                            if (object != null) {
                                try {
                                    fields[i].set(this, object);
                                } catch (IllegalAccessException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    /**
     * 功能说明: 获取任务批量业务处理线程池
     *
     * @return jobBatchBussinessThreadPool 任务批量业务处理线程池
     */
    public JobProcessBusinessThreadPool getJobProcessBusinessThreadPool() {
        return jobProcessBussinessThreadPool;
    }
    
    /**
     * 功能说明: 获取任务处理线程池
     *
     * @return jobProcessThreadPool 任务处理线程池
     */
    public JobProcessThreadPool getJobProcessThreadPool() {
        return jobProcessThreadPool;
    }
    
}
